<?php
/**
 * Created by PhpStorm.
 * User: serafina
 * Date: 2015/9/23
 * Time: 09:50
 */

function mobile_service_genuine_verification_list($parameters){
//    $start  = $parameters['page_count'] * 10;
    $query = db_select('genuine_code', 'G');
    $query->join('product_sku', 'S', 'S.product_sku_id=G.sacfvariety_id');
    $query->fields('G', array('code_id', 'sacfvariety_id', 'code', 'count','timestamp'));
    $query->addField('S', 'variety_name');
    $query->addField('S', 'proportion');
    $query->addField('S', 'SM');
    $query->condition('G.code', $parameters['code'], '=');
//    $query->range($start,10);
    $results = $query->execute();
    $genuine_verification_list = [];
    if(!empty($results)){
        foreach ($results as $result) {
            $result->timestamp = date("Y-m-d",$result->timestamp);
            $genuine_verification_list[] = $result;
        }
        db_update("genuine_code")
            ->fields(array(
                'count' => $result->count + 1,
                'timestamp' => time(),
            ))
            ->condition('code_id', $result->code_id, '=')
            ->execute();
    }
    $object_genuine_verification_list = (object)["data"=>$genuine_verification_list];
    return  $object_genuine_verification_list;
}